package com.netbliz.common.util;
import java.util.Enumeration;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyResourceConfigurer;
/**
 * 获取系统参数和*.properties中的参数
 * @author Administrator
 *
 */
public class ConfigUtil extends PropertyResourceConfigurer {  
    private static final Logger logger = Logger.getLogger(ConfigUtil.class);  
  
    private static Properties properties;  
  
    public static String getConfig(String key) {  
        return properties.getProperty(key);  
    }  
  
    public static String getConfig(String key, String defaultValue) {  
        return properties.getProperty(key, defaultValue);  
    }  
  
    public static void appendProperties(Properties paramProperties) {  
        if (properties == null) {  
            properties = paramProperties;  
        } else {  
            Enumeration enums = paramProperties.propertyNames();  
            while (enums.hasMoreElements()) {  
                String key = (String) enums.nextElement();  
                properties.setProperty(key, paramProperties.getProperty(key));  
                logger.info("add ConfigUtil:  " + key + " = '"  
                        + paramProperties.getProperty(key));  
            }  
        }  
    }  
  
    @Override  
    protected void processProperties(  
            ConfigurableListableBeanFactory paramConfigurableListableBeanFactory,  
            Properties paramProperties) throws BeansException {  
        appendProperties(paramProperties); 
    } 
}  
